import Koa from 'koa'
import Router from 'koa-router'
import koaNunjucks from 'koa-nunjucks-async'
import koaBody from 'koa-body'
import koaStatic from 'koa-static'

import routes from './routes'
const app = new Koa()
const router  = new Router()

const nunjucksOptions = {
  opts: {
      noCache: false,
      throwOnUndefined: false
  },
  filters:{
    publicPath:(path)=>{
      let newPath = path.replace(/\/static/g,'/public').replace(/\.scss/g,'.css');
      return newPath;
    }
  },
  ext: '.html'
};

routes(router,koaBody)

app.use(koaStatic('.'))
app.use(koaNunjucks('views',nunjucksOptions))
app
  .use(router.routes())
  .use(router.allowedMethods())
app.listen(8081, console.log("application is start at port 8081"))